package com.baomidou.mybatisplus.samples.quickstart;

import com.baomidou.mybatisplus.samples.quickstart.mapper.DepMapper;
import com.baomidou.mybatisplus.samples.quickstart.mapper.EmpMapper;
import com.baomidou.mybatisplus.samples.quickstart.pojo.Dep;
import com.baomidou.mybatisplus.samples.quickstart.pojo.Emp;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * @Description : 测试mp的ar模式和普通模式，分段查询
 * Created by cyd on 2021-03-05 09:20:36
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class ObjectTest2 {
    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private DepMapper depMapper;

    private Logger logger= LoggerFactory.getLogger(ObjectTest2.class);

    /**
     * 测试分段查询的第一段
     */
    @Test
    public void test01() {
        Emp emp = new Emp();
        emp = emp.selectById("83ccdadf319414586f3a7b4ac4e4b314");
        System.out.println(emp);
    }

    /**
     * 测试分段查询的第2段
     */
    @Test
    public void test02() {
        Emp emp = new Emp();
        emp = emp.selectById("83ccdadf319414586f3a7b4ac4e4b314");
        //System.out.println(emp);
        Dep dep = new Dep();
        dep = dep.selectById(emp.getDepId());
        emp.setDep(dep);
        System.out.println(emp);

    }

    /**
     * 用mapper测试分段查询的第2段
     * 好处：能用上mp，能根据需求分段查
     * 坏处：多写代码，需要对业务对象关系有较深的了解
     */
    @Test
    public void test03() {
        Emp emp = empMapper.selectById("83ccdadf319414586f3a7b4ac4e4b314");
        Dep dep = depMapper.selectById(emp.getDepId());
        emp.setDep(dep);

        logger.warn(emp.toString());
        //System.out.println(emp);
    }

}
